package net.test.common;

import javax.servlet.ServletContext;

import net.test.directive.CheckboxDirective;
import net.test.util.SpringUtil;



import freemarker.template.TemplateException;

public class FreemarkerManager extends org.apache.struts2.views.freemarker.FreemarkerManager {

	public synchronized freemarker.template.Configuration getConfiguration(ServletContext servletContext) {
		freemarker.template.Configuration config = (freemarker.template.Configuration) servletContext.getAttribute(CONFIG_SERVLET_CONTEXT_KEY);
		if (config == null) {
			try {
				config = createConfiguration(servletContext);
			} catch (TemplateException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			// config.setTemplateExceptionHandler(TemplateExceptionHandler.IGNORE_HANDLER);
			
			CheckboxDirective checkboxDirective = (CheckboxDirective) SpringUtil.getBean("checkboxDirective");
			
			servletContext.setAttribute(CONFIG_SERVLET_CONTEXT_KEY, config);
			
			config.setSharedVariable(CheckboxDirective.TAG_NAME, checkboxDirective);
		}
		config.setWhitespaceStripping(true);
		return config;
	}

}